public class CharacterReplacement {

    public int characterReplacement(String s, int k) {
        int[] nums = new int[26];
        char[] chars = s.toCharArray();
        int l = 0;
        int max = 0;
        for (int i = 0; i < chars.length; i++) {
            ++nums[chars[i] - 'A'];
            max = Math.max(max, nums[chars[i] - 'A']);
            if (i - l + 1 - max > k) {
                --nums[chars[l++] - 'A'];
            }
        }
        return chars.length - l;
    }
}
